#include <bits/stdc++.h>

#define int long long
#define endl "\n"

using namespace std;

inline int pk(int a,int b,int c)
{
    return a+b*3000+c*9000000;
}

int dfs(vector<int> &a,int cur,int red,int blue,unordered_map<int,int> &dp)
{
    if (cur>=a.size())return 0;

    int data=pk(cur,red,blue);
    if (dp.count(data))return dp[data];

    int ans;
    int r=dfs(a,cur+1,a[cur],blue,dp);
    if (red==a[cur])
    {
        r+=a[cur];
    }
    int b=dfs(a,cur+1,red,a[cur],dp);
    if (blue==a[cur])
    {
        b+=a[cur];
    }
    ans=max(r,b);
    return dp[data]=ans;
}

void solve()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)cin>>a[i];

    unordered_map<int,int> dp;
    int ans=dfs(a,0,0,0,dp);

    cout<<ans<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);

    int T;
    cin>>T;
    while(T--)solve();

    return 0;
}



